package com.ruofeng.app.kotlin.common.codegen

import com.ruofeng.app.common.codegen.GeneratorParam
import com.ruofeng.app.common.codegen.KotlinGenerator
import com.ruofeng.app.common.codegen.dsl.DslKotlinGeneratorConfig
import org.beetl.sql.core.SQLManager
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner

/**
 * Created by 邱鹏 on 2017/7/31.
 */
@RunWith(SpringJUnit4ClassRunner::class)
@SpringBootTest
class GenerateDslTest {
    @Autowired lateinit var sqlManager: SQLManager
    @Test
    fun sourceGenCode() {
        val pkgStr = "com.ruofeng.app.privilege.user"
        val btl = "/btl/kotlinGenerator/model.btl"
        var btlList = listOf<String>("/btl/kotlinGenerator/model.btl", "/btl/kotlinGenerator/service.btl", "/btl/kotlinGenerator/mapper.btl", "/btl/kotlinGenerator/controller.btl")
        var model = "/btl/kotlinGenerator/model.btl"
        var service = "/btl/kotlinGenerator/service.btl"
        var controller = "/btl/kotlinGenerator/controller.btl"
        var dao = "/btl/kotlinGenerator/dao.btl"
        DslKotlinGeneratorConfig().apply {
//            paramList ={
//                +generatorParam(){
//
//                }
//                +GeneratorParam().apply {
//                    tableName = "sys_user"
//                    className = "SysUser"
//                    this.btl = "/btl/kotlinGenerator/sql.md.btl"
//                    pkg = pkgStr
//                    fileExtension=".md"
//                }
//            }
        }

        var paramList = listOf<GeneratorParam>(
//                GeneratorParam("sys_user", pkgStr, model, "SysUser"),
//                GeneratorParam("sys_user", pkgStr, controller, "SysUserController"),
//                GeneratorParam("sys_user", pkgStr, service, "SysUserService"),
//                GeneratorParam("sys_user", pkgStr, dao, "SysUserDao"),
                GeneratorParam().apply {
                    tableName = "sys_user"
                    className = "SysUser"
                    this.btl = "/btl/kotlinGenerator/sql.md.btl"
                    pkg = pkgStr
                    fileExtension=".md"
                })
        val gen = KotlinGenerator(sqlManager, paramList)
        gen.gen()
    }
}